package metr;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MainFrame extends JFrame {
    public MainFrame() {
        setTitle("超市库存管理系统");
        setSize(800, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        JPanel panel = new JPanel(new BorderLayout());

        // 顶部标题
        JLabel titleLabel = new JLabel("超市库存管理系统", JLabel.CENTER);
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
        panel.add(titleLabel, BorderLayout.NORTH);

        // 中间按钮区域
        JPanel buttonPanel = new JPanel(new GridLayout(3, 2, 20, 20));
        buttonPanel.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));

        JButton productManageBtn = new JButton("商品信息管理");
        JButton stockInBtn = new JButton("入库管理");
        JButton stockOutBtn = new JButton("出库管理");
        JButton queryBtn = new JButton("查询功能");
        JButton alertBtn = new JButton("库存预警");
        JButton exitBtn = new JButton("退出系统");

        buttonPanel.add(productManageBtn);
        buttonPanel.add(stockInBtn);
        buttonPanel.add(stockOutBtn);
        buttonPanel.add(queryBtn);
        buttonPanel.add(alertBtn);
        buttonPanel.add(exitBtn);

        panel.add(buttonPanel, BorderLayout.CENTER);

        // 底部状态栏
        JLabel statusLabel = new JLabel("欢迎使用超市库存管理系统", JLabel.CENTER);
        panel.add(statusLabel, BorderLayout.SOUTH);

        add(panel);

        // 按钮事件
        productManageBtn.addActionListener(e -> {
            new ProductManagementFrame().setVisible(true);
        });

        stockInBtn.addActionListener(e -> {
            new StockInFrame().setVisible(true);
        });

        stockOutBtn.addActionListener(e -> {
            new StockOutFrame().setVisible(true);
        });

        queryBtn.addActionListener(e -> {
            new QueryFrame().setVisible(true);
        });

        alertBtn.addActionListener(e -> {
            new StockAlertFrame().setVisible(true);
        });

        exitBtn.addActionListener(e -> {
            System.exit(0);
        });
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            new MainFrame().setVisible(true);
        });
    }
}